#include "StdAfx.h"
#include "DevParams.h"
#include "SendCmdToDev.h"
#include "CamOperate.h"
#include "SocketUtil.h"

#define WM_MSG_GET_PARAM_FINISH			(WM_USER + 1043)
#define WM_MSG_GET_CAMERA_INFO			(WM_USER + 1015)
#define WM_MSG_CMDPORT_VER_EER			(WM_USER + 1044)

CDevParams::CDevParams(void)
{
	m_hThreadGetParam = NULL;
	m_hWndNotify = NULL;
	m_nPort = 0;
	m_pCmdToDev = NULL;
	m_hWndGetInfo = NULL;
	m_pchCameraInfo = NULL;
	if (NULL == m_pchCameraInfo)
	{
		m_pchCameraInfo = new char[CAM_INFO_BUFF_SIZE];
	}

	if (m_camOsd.jpegOsd.value.p == NULL)
	{
		m_camOsd.jpegOsd.value.p = new RoseekOsdConfig;
		memset(m_camOsd.jpegOsd.value.p,0,sizeof(RoseekOsdConfig));
	}
	
	if (m_camOsd.h264Osd[0].value.p == NULL)
	{
		m_camOsd.h264Osd[0].value.p = new RoseekOsdConfig;
		memset(m_camOsd.h264Osd[0].value.p,0,sizeof(RoseekOsdConfig));
	}

	if (m_camOsd.h264Osd[1].value.p == NULL)
	{
		m_camOsd.h264Osd[1].value.p = new RoseekOsdConfig;
		memset(m_camOsd.h264Osd[1].value.p,0,sizeof(RoseekOsdConfig));
	}
}


CDevParams::~CDevParams(void)
{
	if (NULL != m_pchCameraInfo)
	{
		delete[] m_pchCameraInfo;
		m_pchCameraInfo = NULL;
	}

	if (m_camOsd.jpegOsd.value.p != NULL)
	{
		delete m_camOsd.jpegOsd.value.p;
		m_camOsd.jpegOsd.value.p = NULL;
	}

	if (m_camOsd.h264Osd[0].value.p != NULL)
	{
		delete m_camOsd.h264Osd[0].value.p;
		m_camOsd.h264Osd[0].value.p = NULL;
	}

	if (m_camOsd.h264Osd[1].value.p == NULL)
	{
		delete m_camOsd.h264Osd[1].value.p;
		m_camOsd.h264Osd[1].value.p = NULL;
	}
}



int CDevParams::OpenObtainParams(HWND hWnd, const char* ip, int port, const char* pUsername, const char* pPassword)
{
	if (NULL != m_hThreadGetParam)
	{
		return -1;
	}

	m_hWndNotify = hWnd;
	m_strIP = ip;
	m_nPort = port;
	m_strUserName = pUsername;
	m_strPassword = pPassword;
	m_hThreadGetParam = (HANDLE)_beginthreadex(NULL, 0, ThreadGetParams, (void*)this, 0, NULL);
	return 0;
}

unsigned __stdcall CDevParams::ThreadGetParams(void* pParam)
{
	int iret = 0;
	USES_CONVERSION;
	CDevParams *pThis = (CDevParams*)pParam;
	char* pchSendBuf = NULL;
	char* pchRecvBuf = NULL;
	char* pMsg = NULL;
	int result = 0;
	CSendCmdToDev *pCmdToDev = pThis->m_pCmdToDev;

	if (pCmdToDev == NULL)
	{
		iret = -100;
		::SendMessage(pThis->m_hWndNotify, WM_MSG_GET_PARAM_FINISH, (WPARAM)iret, 0);
		return 0;
	}

	pchSendBuf = new char[1024*10];
	if (pchSendBuf == NULL)
	{
		iret = -100;
		::SendMessage(pThis->m_hWndNotify, WM_MSG_GET_PARAM_FINISH, (WPARAM)iret, 0);
		return 0;
	}

	//set ip address and set login information
	pCmdToDev->SetDevAddr(pThis->m_strIP.c_str(), pThis->m_nPort);

	//set login address
	pCmdToDev->SetLoginInfo(pThis->m_strUserName.c_str(), pThis->m_strPassword.c_str());

	iret = -1;
	do 
	{
		//get command port version
		iret = pCmdToDev->SendCMD(CMD_GEN_CMD_PORT_VER, CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			::SendMessage(pThis->m_hWndNotify, WM_MSG_GET_PARAM_FINISH, (WPARAM)iret, (LPARAM)(pchRecvBuf+4));
			return 0;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		pThis->m_camCmdPort.nPortVer = *(DWORD*)pchRecvBuf;
		if(pThis->m_camCmdPort.nPortVer != CMD_PORT_VER)
		{
			::PostMessage(pThis->m_hWndNotify, WM_MSG_CMDPORT_VER_EER, 0, 0);
			return 0;
		}

		//get acquisition mode
		iret = pCmdToDev->SendCMD(CMD_ACQ_MODE, CMD_METHOD_GET_RANGE);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		memcpy(&pThis->m_camExpo.acqMode.range, (BYTE*)pchRecvBuf + 4,sizeof(VALUE_RANGE));

		iret = pCmdToDev->SendCMD(CMD_ACQ_MODE, CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camExpo.acqMode.valid = TRUE;
			pThis->m_camExpo.acqMode.value.ui = *(DWORD*)pchRecvBuf;
			pThis->m_camExpo.acqMode.type = PARAM_TYPE_VALUE_RANGE;
		}

		//get RTSP local address
		*(DWORD*)pchSendBuf = 0;
		iret = pCmdToDev->SendCMD(CMD_NET_RTSP_LOCAL,CMD_METHOD_GET,pchSendBuf,4);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camStream.rtspLocal[0].valid = TRUE;
			pThis->m_camStream.rtspLocal[0].strValue = pchRecvBuf;
			pThis->m_camStream.rtspLocal[0].type = PARAM_TYPE_STRING;
		}
		*(DWORD*)pchSendBuf = 1;
		pCmdToDev->SendCMD(CMD_NET_RTSP_LOCAL,CMD_METHOD_GET,pchSendBuf,4);
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camStream.rtspLocal[1].valid = TRUE;
			pThis->m_camStream.rtspLocal[1].strValue = pchRecvBuf;
			pThis->m_camStream.rtspLocal[1].type = PARAM_TYPE_STRING;
		}

		//get command class 
		iret = pCmdToDev->SendCMD(CMD_GEN_CMD_CLASS, CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		pThis->m_camCmdPort.nClass = *(DWORD*)pchRecvBuf;

		//get command version
		iret = pCmdToDev->SendCMD(CMD_GEN_CLASS_VER, CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		pThis->m_camCmdPort.nClassVer = *(DWORD*)pchRecvBuf;

		//get network port list
		iret = pCmdToDev->SendCMD(CMD_NET_MODULE_PORT_NUM, CMD_METHOD_PARAMS_LIST);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		pThis->LoadPortNumInfo((BYTE*)pchRecvBuf);

		//get device information
		iret = pThis->QueryDevInfo(pThis->m_strIP.c_str(), pThis->FindPortNum(_T("Device information upload port")),
			pThis->m_pchCameraInfo, CAM_INFO_BUFF_SIZE);
		if (0 == iret)
		{
			::PostMessage(pThis->m_hWndNotify, WM_MSG_GET_CAMERA_INFO, (WPARAM)iret, 0);
			iret = -1;
			break;
		}
		pThis->AnalyCameraInfo(pThis->m_pchCameraInfo);

		//get CCD sensor resolution
		iret = pCmdToDev->SendCMD(CMD_INFO_CCD_RESOLUTION, CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		pThis->m_camState.nSensorWidth = *(DWORD*)pchRecvBuf;
		pThis->m_camState.nSensorHeight = *(DWORD*)(pchRecvBuf+4);

		//get SD card support
		iret = pCmdToDev->SendCMD(CMD_SD_SUPPORT, CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		pThis->m_camStore.supportSD.value.ui = *(DWORD*)pchRecvBuf;
		pThis->m_camStore.supportSD.valid = TRUE;
		pThis->m_camStore.supportSD.type = PARAM_TYPE_VALUE_RANGE;

		//all necessary information have been obtained, display image on dialog
//		::PostMessage(g_pMainViewer->GetSafeHwnd(),WM_MSG_SHOW_ALL_VIEW,0,0);

		//get exposure parameters
		BOOL fault = TRUE;

		for (int i=0; i<2; i++)
		{
			//get adjust mode
			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_ACQ_PARA_ADJUST,CMD_METHOD_GET,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camExpo.adjustMode[i].valid = TRUE;
				pThis->m_camExpo.adjustMode[i].value.ui = *(DWORD*)pchRecvBuf;
			}

			//get shutter time
			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_ACQ_SHUTTIME,CMD_METHOD_GET,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camExpo.shutterTime[i].valid = TRUE;
				pThis->m_camExpo.shutterTime[i].value.ui = *(DWORD*)pchRecvBuf;

				iret = pCmdToDev->SendCMD(CMD_ACQ_SHUTTIME,CMD_METHOD_GET_RANGE);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				if (result == CMD_PROCESS_SUCCESS)
				{
					memcpy_s(&pThis->m_camExpo.shutterTime[i].range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));
				}
				else
				{
					pThis->m_camExpo.shutterTime[i].range.minValue.ui = 0; 
					pThis->m_camExpo.shutterTime[i].range.maxValue.ui = 36000;
					pThis->m_camExpo.shutterTime[i].range.step.ui = 1;					
				}
			}

			//get shutter time upper limit
			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_ACQ_SHUT_LIMIT,CMD_METHOD_GET,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camExpo.shutterTimeLimit[i].valid = TRUE;
				pThis->m_camExpo.shutterTimeLimit[i].value.ui = *(DWORD*)pchRecvBuf;

				iret = pCmdToDev->SendCMD(CMD_ACQ_SHUT_LIMIT,CMD_METHOD_GET_RANGE);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				if (result == CMD_PROCESS_SUCCESS)
				{
					memcpy_s(&pThis->m_camExpo.shutterTimeLimit[i].range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));
				}
				else
				{
					pThis->m_camExpo.shutterTimeLimit[i].range.minValue.ui = 0; 
					pThis->m_camExpo.shutterTimeLimit[i].range.maxValue.ui = 36000;
					pThis->m_camExpo.shutterTimeLimit[i].range.step.ui = 1;
				}
			}

			//get shutter time lower limit
			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_ACQ_SHUT_LOWLIMIT,CMD_METHOD_GET,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camExpo.shutterTimeLowLimit[i].valid = TRUE;
				pThis->m_camExpo.shutterTimeLowLimit[i].value.ui = *(DWORD*)pchRecvBuf;

				iret = pCmdToDev->SendCMD(CMD_ACQ_SHUT_LOWLIMIT,CMD_METHOD_GET_RANGE);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				if (result == CMD_PROCESS_SUCCESS)
				{
					memcpy_s(&pThis->m_camExpo.shutterTimeLowLimit[i].range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));
				}
				else
				{
					pThis->m_camExpo.shutterTimeLowLimit[i].range.minValue.ui = 0; 
					pThis->m_camExpo.shutterTimeLowLimit[i].range.maxValue.ui = 36000;
					pThis->m_camExpo.shutterTimeLowLimit[i].range.step.ui = 1;
				}
			}

			//get gain
			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_ACQ_GAIN,CMD_METHOD_GET,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camExpo.gain[i].valid = TRUE;
				pThis->m_camExpo.gain[i].value.f = *(float*)pchRecvBuf;

				iret = pCmdToDev->SendCMD(CMD_ACQ_GAIN,CMD_METHOD_GET_RANGE);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				if (result == CMD_PROCESS_SUCCESS)
				{
					memcpy_s(&pThis->m_camExpo.gain[i].range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));
				}
				else
				{
					pThis->m_camExpo.gain[i].range.minValue.f = 0.0; 
					pThis->m_camExpo.gain[i].range.maxValue.f = 36.0;
					pThis->m_camExpo.gain[i].range.step.f = 0.0;
				}
			}

			//get gain limit
			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_ACQ_GAIN_LIMIT,CMD_METHOD_GET,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camExpo.gainLimit[i].valid = TRUE;
				pThis->m_camExpo.gainLimit[i].value.f = *(float*)pchRecvBuf;

				iret = pCmdToDev->SendCMD(CMD_ACQ_GAIN_LIMIT,CMD_METHOD_GET_RANGE);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				if (result == CMD_PROCESS_SUCCESS)
				{
					memcpy_s(&pThis->m_camExpo.gainLimit[i].range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));
				}
				else
				{
					pThis->m_camExpo.gainLimit[i].range.minValue.f = 0.0; 
					pThis->m_camExpo.gainLimit[i].range.maxValue.f = 36.0;
					pThis->m_camExpo.gainLimit[i].range.step.f = 0.0;					
				}
			}

			//get expected brightness
			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_ACQ_MEAN,CMD_METHOD_GET,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camExpo.expectBright[i].valid = TRUE;
				pThis->m_camExpo.expectBright[i].value.ui = *(DWORD*)pchRecvBuf;
			}
			fault = FALSE;
		}

		if (fault)
		{
			break;
		}

		//get trigger frame parameters adjustment mode(only of Chameleon)
		iret = pCmdToDev->SendCMD(CMD_ACQ_TRGFRAME_ADJMODE,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camExpo.trgFrameAdjMode.valid = TRUE;
			pThis->m_camExpo.trgFrameAdjMode.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get trigger frame shut time(only of Chameleon)
		iret = pCmdToDev->SendCMD(CMD_ACQ_TRGFRAME_SHUTTIME,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camExpo.trgFrameShuttime.valid = TRUE;
			pThis->m_camExpo.trgFrameShuttime.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get trigger frame gain(only of Chameleon)
		iret = pCmdToDev->SendCMD(CMD_ACQ_TRGFRAME_GAIN,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camExpo.trgFrameGain.valid = TRUE;
			pThis->m_camExpo.trgFrameGain.value.f = *(float*)pchRecvBuf;
		}

		//get metering region
		*(DWORD*)pchSendBuf = 1;
		iret = pCmdToDev->SendCMD(CMD_ACQ_METER_REGION,CMD_METHOD_GET,pchSendBuf,4);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camExpo.meteringRegion[0].valid = TRUE;
			pThis->m_camExpo.meteringRegion[1].valid = TRUE;
			pThis->m_camExpo.meteringRegion[2].valid = TRUE;
			pThis->m_camExpo.meteringRegion[3].valid = TRUE;
			pThis->m_camExpo.meteringRegion[0].value.ui = *(DWORD*)pchRecvBuf;
			pThis->m_camExpo.meteringRegion[1].value.ui = *(DWORD*)(pchRecvBuf+4);
			pThis->m_camExpo.meteringRegion[2].value.ui = *(DWORD*)(pchRecvBuf+8);
			pThis->m_camExpo.meteringRegion[3].value.ui = *(DWORD*)(pchRecvBuf+12);
		}

		//get white balance state
		iret = pCmdToDev->SendCMD(CMD_PROC_AUTO_WB,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camPreProc.wbEn.valid = TRUE;
			pThis->m_camPreProc.wbEn.value.ui = *(DWORD*)pchRecvBuf;
		}

		//list white balance environment
		iret = pCmdToDev->SendCMD(CMD_PROC_WB_ENVIRONMENT,CMD_METHOD_PARAMS_LIST);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camPreProc.wbEnviron.valid = TRUE;
			pThis->m_camPreProc.wbEnviron.type = PARAM_TYPE_STRING_LIST;
			DWORD cnt = *(DWORD*)pchRecvBuf;
			pThis->m_camPreProc.wbEnviron.list.clear();
			for (DWORD i=0; i<cnt; i++)
			{
				std::string strInset = (char*)(pchRecvBuf + 4 + i*32);
				pThis->m_camPreProc.wbEnviron.list.push_back(strInset);
			}

			//get white balance environment
			iret = pCmdToDev->SendCMD(CMD_PROC_WB_ENVIRONMENT,CMD_METHOD_GET);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			pThis->m_camPreProc.wbEnviron.strValue = (char*)pchRecvBuf;
		}

		//get white balance parameters
		iret = pCmdToDev->SendCMD(CMD_PROC_WB_PARAMS,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camPreProc.wbCol[0].valid = TRUE;
			pThis->m_camPreProc.wbCol[1].valid = TRUE;
			pThis->m_camPreProc.wbCol[2].valid = TRUE;
			pThis->m_camPreProc.wbCol[0].value.f = *(float*)pchRecvBuf;
			pThis->m_camPreProc.wbCol[1].value.f = *(float*)(pchRecvBuf+4);
			pThis->m_camPreProc.wbCol[2].value.f = *(float*)(pchRecvBuf+8);
		}

		//get white balance sensitivity
		iret = pCmdToDev->SendCMD(CMD_ACQ_AFE_LEVEL,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camAcq.afelv.valid = TRUE;
			pThis->m_camAcq.afelv.value.ui = *(DWORD*)pchRecvBuf;
			iret = pCmdToDev->SendCMD(CMD_ACQ_AFE_LEVEL,CMD_METHOD_GET_RANGE);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				memcpy_s(&pThis->m_camAcq.afelv.range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));
			}
		}


		//get LUT state
		iret = pCmdToDev->SendCMD(CMD_PROC_LUT,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camPreProc.lutEn.valid = TRUE;
			pThis->m_camPreProc.lutEn.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get LUT mode
		*(DWORD*)pchSendBuf = 0;
		iret = pCmdToDev->SendCMD(CMD_PROC_LUT_MODE,CMD_METHOD_GET,pchSendBuf,4);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camPreProc.lutMode.valid = TRUE;
			pThis->m_camPreProc.lutMode.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get LUT gamma
		*(DWORD*)pchSendBuf = 0;
		iret = pCmdToDev->SendCMD(CMD_PROC_GAMMA,CMD_METHOD_GET,pchSendBuf,4);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camPreProc.lutGamma.valid = TRUE;
			pThis->m_camPreProc.lutGamma.value.f = *(float*)pchRecvBuf;
		}

		//get digital gain
		iret = pCmdToDev->SendCMD(CMD_PROC_DIGITAL_GAIN,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camPreProc.digiGain.valid = TRUE;
			pThis->m_camPreProc.digiGain.value.f = *(float*)pchRecvBuf;
			
			//get parameters range
			iret = pCmdToDev->SendCMD(CMD_PROC_DIGITAL_GAIN,CMD_METHOD_GET_RANGE);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				memcpy_s(&pThis->m_camPreProc.digiGain.range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));
			}

		}

		//get color saturation
		iret = pCmdToDev->SendCMD(CMD_PROC_COLOR,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camPreProc.colorSaturation.valid = TRUE;
			pThis->m_camPreProc.colorSaturation.value.f = *(float*)pchRecvBuf;

			//get parameters range
			iret = pCmdToDev->SendCMD(CMD_PROC_COLOR,CMD_METHOD_GET_RANGE);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				memcpy_s(&pThis->m_camPreProc.colorSaturation.range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));
			}
		}

		//get denoise level
		iret = pCmdToDev->SendCMD(CMD_PROC_DENOISE,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camPreProc.imgDenoise.valid = TRUE;
			pThis->m_camPreProc.imgDenoise.value.ui = *(DWORD*)pchRecvBuf;

			//get parameters range
			iret = pCmdToDev->SendCMD(CMD_PROC_DENOISE,CMD_METHOD_GET_RANGE);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				memcpy_s(&pThis->m_camPreProc.imgDenoise.range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));
			}
		}

		//get enhancement level
		iret = pCmdToDev->SendCMD(CMD_PROC_ENHANCEMENT,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camPreProc.imgEnahance.valid = TRUE;
			pThis->m_camPreProc.imgEnahance.value.ui = *(DWORD*)pchRecvBuf;

			//get parameters range
			iret = pCmdToDev->SendCMD(CMD_PROC_ENHANCEMENT,CMD_METHOD_GET_RANGE);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				memcpy_s(&pThis->m_camPreProc.imgEnahance.range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));
			}
		}

		//list current image acquisition format
		iret = pCmdToDev->SendCMD(CMD_ACQ_FORMAT,CMD_METHOD_PARAMS_LIST);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camAcq.format.valid = TRUE;
			pThis->m_camAcq.format.type = PARAM_TYPE_STRING_LIST;
			DWORD cnt = *(DWORD*)pchRecvBuf;
			pThis->m_camAcq.format.list.clear();
			for (DWORD i=0; i<cnt; i++)
			{
				std::string strInset = (char*)(pchRecvBuf + 4 + i*32);
				pThis->m_camAcq.format.list.push_back(strInset);
			}

			//get format
			iret = pCmdToDev->SendCMD(CMD_ACQ_FORMAT,CMD_METHOD_GET);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			pThis->m_camAcq.format.strValue = (char*)pchRecvBuf;
		}

		//get image rotation state
		iret = pCmdToDev->SendCMD(CMD_ACQ_ROTATION,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camAcq.rotate.valid = TRUE;
			pThis->m_camAcq.rotate.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get image acquisition FPS
		iret = pCmdToDev->SendCMD(CMD_ACQ_FPS,CMD_METHOD_PARAMS_LIST);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camAcq.fps.valid = TRUE;
			pThis->m_camAcq.fps.type = PARAM_TYPE_STRING_LIST;
			DWORD cnt = *(DWORD*)pchRecvBuf;
			pThis->m_camAcq.fps.list.clear();
			for (DWORD i=0; i<cnt; i++)
			{
				std::string strInset = (char*)(pchRecvBuf + 4 + i*32);
				pThis->m_camAcq.fps.list.push_back(strInset);
			}

			//get FPS
			iret = pCmdToDev->SendCMD(CMD_ACQ_FPS,CMD_METHOD_GET);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			pThis->m_camAcq.fps.strValue = (char*)pchRecvBuf;
		}
		else if(result == CMD_ERR_INVALID_METHOD)
		{
			iret = pCmdToDev->SendCMD(CMD_ACQ_FPS,CMD_METHOD_GET_RANGE);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pThis->m_camAcq.fps.valid = TRUE;
			pThis->m_camAcq.fps.type = PARAM_TYPE_VALUE_RANGE;
			memcpy_s(&pThis->m_camAcq.fps.range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));

			//get FPS
			iret = pCmdToDev->SendCMD(CMD_ACQ_FPS,CMD_METHOD_GET);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			pThis->m_camAcq.fps.value.f = *(float*)pchRecvBuf;
		}

		//get HDR level
		iret = pCmdToDev->SendCMD(CMD_PROC_HDR_LEVEL,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camPreProc.hdrLevel.valid = TRUE;
			pThis->m_camPreProc.hdrLevel.value.ui = *(DWORD*)pchRecvBuf;

			//get parameters range
			iret = pCmdToDev->SendCMD(CMD_PROC_HDR_LEVEL,CMD_METHOD_GET_RANGE);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				memcpy_s(&pThis->m_camPreProc.hdrLevel.range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));
			}
		}

		//constrast
		pThis->m_camPreProc.constrast.valid = TRUE;
		pThis->m_camPreProc.constrast.value.ui = (DWORD)(pThis->m_camPreProc.lutGamma.value.f*100.0);
		pThis->m_camPreProc.constrast.range.minValue.ui = 1;
		pThis->m_camPreProc.constrast.range.maxValue.ui = 200;
		pThis->m_camPreProc.constrast.range.step.ui = 1;

		//get H264 streaming parameters
		fault = TRUE;
		for (int i=0; i<2; i++)
		{
			//get h264 resolution
			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_H264_RESOLUTION,CMD_METHOD_PARAMS_LIST,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camStream.resolution[i].valid = TRUE;
				pThis->m_camStream.resolution[i].type = PARAM_TYPE_STRING_LIST;
				pThis->m_camStream.resolution[i].list.clear();
				DWORD cnt = *(DWORD*)pchRecvBuf;
				for (DWORD j=0; j<cnt; j++)
				{
					std::string strInset = (char*)(pchRecvBuf + 4 + j*32);
					pThis->m_camStream.resolution[i].list.push_back(strInset);
				}

				//get resolution
				iret = pCmdToDev->SendCMD(CMD_H264_RESOLUTION,CMD_METHOD_GET,pchSendBuf,4);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				pThis->m_camStream.resolution[i].strValue = (char*)pchRecvBuf;
			}

			//get h264 code rate
			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_H264_CODE_RATE,CMD_METHOD_GET,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camStream.codeRate[i].valid = TRUE;
				pThis->m_camStream.codeRate[i].value.ui = *(DWORD*)pchRecvBuf;

				//get range
				*(DWORD*)pchSendBuf = 1;
				iret = pCmdToDev->SendCMD(CMD_H264_CODE_RATE,CMD_METHOD_GET_RANGE,pchSendBuf,4);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				if (result == CMD_PROCESS_SUCCESS)
				{
					memcpy_s(&pThis->m_camStream.codeRate[i].range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));
				}
				else
				{
					pThis->m_camStream.codeRate[i].range.maxValue.ui = 16000;
					pThis->m_camStream.codeRate[i].range.minValue.ui = 48;
					pThis->m_camStream.codeRate[i].range.step.ui = 1;
				}
			}

			//get h264 fps
			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_H264_ENC_FPS,CMD_METHOD_PARAMS_LIST,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camStream.fps[i].valid = TRUE;
				pThis->m_camStream.fps[i].type = PARAM_TYPE_STRING_LIST;
				DWORD cnt = *(DWORD*)pchRecvBuf;
				pThis->m_camStream.fps[i].list.clear();
				for (DWORD j=0; j<cnt; j++)
				{
					std::string strInset = (char*)(pchRecvBuf + 4 + j*32);
					pThis->m_camStream.fps[i].list.push_back(strInset);
				}

				//get FPS
				iret = pCmdToDev->SendCMD(CMD_H264_ENC_FPS,CMD_METHOD_GET,pchSendBuf,4);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				pThis->m_camStream.fps[i].strValue = (char*)pchRecvBuf;
			}
			else if(result == CMD_ERR_INVALID_METHOD)
			{
				iret = pCmdToDev->SendCMD(CMD_H264_ENC_FPS,CMD_METHOD_GET_RANGE,pchSendBuf,4);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pThis->m_camStream.fps[i].valid = TRUE;
				pThis->m_camStream.fps[i].type = PARAM_TYPE_VALUE_RANGE;
				memcpy_s(&pThis->m_camStream.fps[i].range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));

				//get FPS
				iret = pCmdToDev->SendCMD(CMD_H264_ENC_FPS,CMD_METHOD_GET,pchSendBuf,4);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				pThis->m_camStream.fps[i].value.ui = *(DWORD*)pchRecvBuf;
			}

			//get H264 profile level
			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_H264_ENC_PROFILE,CMD_METHOD_GET,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camStream.profile[i].valid = TRUE;
				pThis->m_camStream.profile[i].value.ui = *(DWORD*)pchRecvBuf;

				//get range
				iret = pCmdToDev->SendCMD(CMD_H264_ENC_PROFILE,CMD_METHOD_GET_RANGE,pchSendBuf,4);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				if (result == CMD_PROCESS_SUCCESS)
				{
					memcpy_s(&pThis->m_camStream.profile[i].range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));
				}
			}

			//get H264 I frame interval
			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_H264_IFRAME_INTERVAL,CMD_METHOD_GET,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camStream.iFrame[i].valid = TRUE;
				pThis->m_camStream.iFrame[i].value.ui = *(DWORD*)pchRecvBuf;

				//get range
				iret = pCmdToDev->SendCMD(CMD_H264_IFRAME_INTERVAL,CMD_METHOD_GET_RANGE,pchSendBuf,4);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				if (result == CMD_PROCESS_SUCCESS)
				{
					memcpy_s(&pThis->m_camStream.iFrame[i].range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));
				}
			}

			fault = FALSE;
		}
		
		if (fault)
		{
			break;
		}

		//get h264 streaming denoise mode and level
		iret = pCmdToDev->SendCMD(CMD_H264_DENOISE,CMD_METHOD_PARAMS_LIST);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camStream.denoiseMode.valid = TRUE;
			pThis->m_camStream.denoiseMode.type = PARAM_TYPE_STRING_LIST;
			DWORD cnt = *(DWORD*)pchRecvBuf;
			DWORD levelCnt = *(DWORD*)(pchRecvBuf+4);
			pThis->m_camStream.denoiseMode.list.clear();
			for (DWORD i=0; i<cnt; i++)
			{
				std::string strInset = (char*)(pchRecvBuf + 8 + i*32);
				pThis->m_camStream.denoiseMode.list.push_back(strInset);
			}

			pThis->m_camStream.denoiseLevel.valid = TRUE;
			pThis->m_camStream.denoiseLevel.type = PARAM_TYPE_STRING_LIST;
			pThis->m_camStream.denoiseLevel.list.clear();
			for (DWORD i=0; i<levelCnt; i++)
			{
				std::string strInset = (char*)(pchRecvBuf + 8 + 32*cnt + i*32);
				pThis->m_camStream.denoiseLevel.list.push_back(strInset);
			}

			//get format
			iret = pCmdToDev->SendCMD(CMD_H264_DENOISE,CMD_METHOD_GET);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			pThis->m_camStream.denoiseMode.strValue = (char*)pchRecvBuf;
			pThis->m_camStream.denoiseLevel.strValue = (char*)(pchRecvBuf+32);
		}

		//get h264 LUT state
		iret = pCmdToDev->SendCMD(CMD_PROC_ASIC_LUT,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camStream.lutEn.valid = TRUE;
			pThis->m_camStream.lutEn.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get h264 LUT mode
		iret = pCmdToDev->SendCMD(CMD_PROC_ASIC_LUT_MODE,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camStream.lutMode.valid = TRUE;
			pThis->m_camStream.lutMode.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get h264 LUT gamma
		*(DWORD*)pchSendBuf = 0;
		iret = pCmdToDev->SendCMD(CMD_PROC_ASIC_GAMMA,CMD_METHOD_GET,pchSendBuf,4);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camStream.lutGamma.valid = TRUE;
			pThis->m_camStream.lutGamma.value.f = *(float*)pchRecvBuf;
		}

		//get hdmi interface output
		iret = pCmdToDev->SendCMD(CMD_H264_HDMI,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camStream.hdmi.valid = TRUE;
			pThis->m_camStream.hdmi.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get cvbs interface output
		iret = pCmdToDev->SendCMD(CMD_H264_CVBS,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camStream.cvbs.valid = TRUE;
			pThis->m_camStream.cvbs.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get JPEG picture output state
		iret = pCmdToDev->SendCMD(CMD_ACQ_JPEG_OUTPUT,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == 0)
		{
			pThis->m_camJpeg.enable.valid = TRUE;
			pThis->m_camJpeg.enable.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get JPEG encoding output FPS
		iret = pCmdToDev->SendCMD(CMD_JPEG_ENC_FPS,CMD_METHOD_PARAMS_LIST);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camJpeg.fps.valid = TRUE;
			pThis->m_camJpeg.fps.type = PARAM_TYPE_STRING_LIST;
			DWORD cnt = *(DWORD*)pchRecvBuf;
			pThis->m_camJpeg.fps.list.clear();
			for (DWORD i=0; i<cnt; i++)
			{
				std::string strInset = (char*)(pchRecvBuf + 4 + i*32);
				pThis->m_camJpeg.fps.list.push_back(strInset);
			}

			//get FPS
			iret = pCmdToDev->SendCMD(CMD_JPEG_ENC_FPS,CMD_METHOD_GET);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			pThis->m_camJpeg.fps.strValue = (char*)pchRecvBuf;
		}
		else if(result == CMD_ERR_INVALID_METHOD)
		{
			iret = pCmdToDev->SendCMD(CMD_JPEG_ENC_FPS,CMD_METHOD_GET_RANGE);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pThis->m_camJpeg.fps.valid = TRUE;
			pThis->m_camJpeg.fps.type = PARAM_TYPE_VALUE_RANGE;
			memcpy_s(&pThis->m_camJpeg.fps.range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));

			//get FPS
			iret = pCmdToDev->SendCMD(CMD_JPEG_ENC_FPS,CMD_METHOD_GET);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			pThis->m_camJpeg.fps.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get JPEG encoding resolution
		iret = pCmdToDev->SendCMD(CMD_ACQ_IMG_RESOLUTION,CMD_METHOD_PARAMS_LIST);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camJpeg.resolution.valid = TRUE;
			pThis->m_camJpeg.resolution.type = PARAM_TYPE_STRING_LIST;
			DWORD cnt = *(DWORD*)pchRecvBuf;
			pThis->m_camJpeg.resolution.list.clear();
			for (DWORD i=0; i<cnt; i++)
			{
				std::string strInset = (char*)(pchRecvBuf + 4 + i*32);
				pThis->m_camJpeg.resolution.list.push_back(strInset);
			}

			//get resolution
			iret = pCmdToDev->SendCMD(CMD_ACQ_IMG_RESOLUTION,CMD_METHOD_GET,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			pThis->m_camJpeg.resolution.strValue = (char*)pchRecvBuf;
		}

		//get JPEG encoding quality
		iret = pCmdToDev->SendCMD(CMD_JPEG_QUALITY,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camJpeg.quality.valid = TRUE;
			pThis->m_camJpeg.quality.value.ui = *(DWORD*)pchRecvBuf;
		}
		iret = pCmdToDev->SendCMD(CMD_JPEG_QUALITY,CMD_METHOD_GET_RANGE);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			memcpy_s(&pThis->m_camJpeg.quality.range,sizeof(VALUE_RANGE),pchRecvBuf + 4,sizeof(VALUE_RANGE));
		}
		

		//set IP address
		pThis->m_camNet.ip.valid = TRUE;
		pThis->m_camNet.ip.value.ui = inet_addr(pThis->m_strIP.c_str());

		//get MAC address		
		iret = pCmdToDev->SendCMD(CMD_NET_MAC_ADDR,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camNet.mac.valid = TRUE;
			pThis->m_camNet.mac.type = PARAM_TYPE_STRING;
			pThis->m_camNet.mac.strValue = strFormat("%02X-%02X-%02X-%02X-%02X-%02X",*(BYTE*)pchRecvBuf,*(BYTE*)(pchRecvBuf+1),
				*(BYTE*)(pchRecvBuf+2),*(BYTE*)(pchRecvBuf+3),*(BYTE*)(pchRecvBuf+4),*(BYTE*)(pchRecvBuf+5));
		}

		iret = pCmdToDev->SendCMD(CMD_TIME_ZONE,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		//get time zone
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camNet.timeZone.valid = TRUE;
			pThis->m_camNet.timeZone.value.i = *(DWORD*)pchRecvBuf;
		}
				
		//get filter state
		iret = pCmdToDev->SendCMD(CMD_OPT_SWITCH,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camIO.filterSwitch.valid = TRUE;
			pThis->m_camIO.filterSwitch.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get power sync state
		iret = pCmdToDev->SendCMD(CMD_POWER_SYNC,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camIO.pwrSyncEn.valid = TRUE;
			pThis->m_camIO.pwrSyncEn.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get power sync phase
		iret = pCmdToDev->SendCMD(CMD_POWER_SYNC_PHASE,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camIO.pwrSyncPhase.valid = TRUE;
			pThis->m_camIO.pwrSyncPhase.value.ui = *(DWORD*)pchRecvBuf;
		}
		

		iret = pCmdToDev->SendCMD(CMD_POWER_SYNC_DELAY, CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camIO.pwrSyncDelay.valid = TRUE;
			pThis->m_camIO.pwrSyncDelay.value.ui = *(DWORD*)pchRecvBuf;

			iret = pCmdToDev->SendCMD(CMD_POWER_SYNC_DELAY, CMD_METHOD_GET_RANGE);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			if (result == CMD_PROCESS_SUCCESS)
			{
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				memcpy_s(&pThis->m_camIO.pwrSyncDelay.range,sizeof(ParamRange),pchRecvBuf+4,sizeof(ParamRange));
			}
		}


		//get IO num
		iret = pCmdToDev->SendCMD(CMD_IO_NUM,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camIO.ioNum.value.ui = *(DWORD*)pchRecvBuf;

			if (pThis->m_camIO.ioNum.value.ui <= 12)
			{
				pThis->m_camIO.ioNum.valid = TRUE;
			}
			else
			{
				pThis->m_camIO.ioNum.valid = FALSE;
			}
		}
		
		fault = FALSE;
		if (pThis->m_camIO.ioNum.valid)
		{
			int cnt = 0;
			cnt = pThis->m_camIO.ioNum.value.ui;
			for (int i=0; i<cnt; i++)
			{
				*(DWORD*)pchSendBuf = i;
				iret = pCmdToDev->SendCMD(CMD_IO_GPIO_CONFIG, CMD_METHOD_GET, pchSendBuf, 4);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				if (result == CMD_PROCESS_SUCCESS)
				{
					pThis->m_camIO.ioConfig[i].value.ui= *(DWORD*)pchRecvBuf;
					pThis->m_camIO.ioConfig[i].valid = TRUE;
				}
			}
			fault = TRUE;
		}

		if (!fault)
		{
			break;
		}

		//get ISO_IN num
		*(DWORD*)pchRecvBuf = 0;
		iret = pCmdToDev->SendCMD(CMD_ISO_NUM,CMD_METHOD_GET,pchRecvBuf,4);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{	
			pThis->m_camIO.isoInNum.value.ui = *(DWORD*)pchRecvBuf;
			pThis->m_camIO.isoInNum.valid = TRUE;
		}

		fault = FALSE;
		if (pThis->m_camIO.isoInNum.valid)
		{
			int cnt = 0;
			cnt = pThis->m_camIO.isoInNum.value.ui;
			for (int i=0; i<cnt; i++)
			{
				*(DWORD*)pchSendBuf = 0;
				*(DWORD*)(pchSendBuf+4) = i;
				iret = pCmdToDev->SendCMD(CMD_IO_ISO_CONFIG, CMD_METHOD_GET, pchSendBuf, 8);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				if (result == CMD_PROCESS_SUCCESS)
				{
					pThis->m_camIO.isoInConfig[i].value.ui = *(DWORD*)pchRecvBuf;
					pThis->m_camIO.isoInConfig[i].valid = TRUE;
				}
			}
			fault = TRUE;
		}
		if (!fault)
		{
			break;
		}

		//get ISO_out num
		*(DWORD*)pchRecvBuf = 1;
		iret = pCmdToDev->SendCMD(CMD_ISO_NUM,CMD_METHOD_GET,pchRecvBuf,8);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camIO.isoOutNum.valid = TRUE;
			pThis->m_camIO.isoOutNum.value.ui = *(DWORD*)pchRecvBuf;
		}

		fault = FALSE;
		if (pThis->m_camIO.isoOutNum.valid)
		{
			int cnt = 0;
			cnt = pThis->m_camIO.isoOutNum.value.ui;
			for (int i=0; i<cnt; i++)
			{
				*(DWORD*)pchSendBuf = 1;
				*(DWORD*)(pchSendBuf+4) = i;
				iret = pCmdToDev->SendCMD(CMD_IO_ISO_CONFIG, CMD_METHOD_GET, pchSendBuf, 8);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				if (result == CMD_PROCESS_SUCCESS)
				{
					pThis->m_camIO.isoOutConfig[i].value.ui = *(DWORD*)pchRecvBuf;
					pThis->m_camIO.isoOutConfig[i].valid = TRUE;
				}
			}
			fault = TRUE;
		}
		if (!fault)
		{
			break;
		}

		//get LED Driver mode
		iret = pCmdToDev->SendCMD(CMD_IO_LEDDRIVER_MODE,CMD_METHOD_GET,NULL,0);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camIO.ledDriverMode.valid = TRUE;
			pThis->m_camIO.ledDriverMode.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get LED Driver strength
		iret = pCmdToDev->SendCMD(CMD_IO_LEDDRIVER_STRENGTH,CMD_METHOD_GET,NULL,0);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camIO.ledDriverStrength.valid = TRUE;
			pThis->m_camIO.ledDriverStrength.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get TrgMode flash lamp output state
		*(DWORD*)pchSendBuf = TrgMode;
		iret = pCmdToDev->SendCMD(CMD_IO_FLASH_OUTPUT,CMD_METHOD_GET,pchSendBuf,4);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camIO.trgFlashEn.valid = TRUE;
			pThis->m_camIO.trgFlashEn.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get FconMode flash lamp output state
		*(DWORD*)pchSendBuf = FconMode;
		iret = pCmdToDev->SendCMD(CMD_IO_FLASH_OUTPUT,CMD_METHOD_GET,pchSendBuf,4);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camIO.fconFlashEn.valid = TRUE;
			pThis->m_camIO.fconFlashEn.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get TrgMode Flash lamp Pre-output
		*(DWORD*)pchSendBuf = TrgMode;
		iret = pCmdToDev->SendCMD(CMD_IO_FLASH_PRE_OUTPUT,CMD_METHOD_GET,pchSendBuf,4);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camIO.trgFlashPre.valid = TRUE;
			pThis->m_camIO.trgFlashPre.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get FconMode Flash lamp Pre-output
		*(DWORD*)pchSendBuf = FconMode;
 		iret = pCmdToDev->SendCMD(CMD_IO_FLASH_PRE_OUTPUT,CMD_METHOD_GET,pchSendBuf,4);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camIO.fconFlashPre.valid = TRUE;
			pThis->m_camIO.fconFlashPre.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get flash lamp output pulse width
		iret = pCmdToDev->SendCMD(CMD_IO_FLASH_PULSE_WIDTH,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camIO.flashPulseWidth.valid = TRUE;
			pThis->m_camIO.flashPulseWidth.value.ui = *(DWORD*)pchRecvBuf;
		}

		//list supported flash lamp strobe output frequency
		iret = pCmdToDev->SendCMD(CMD_IO_FLASH_STROBE_FREQ,CMD_METHOD_PARAMS_LIST);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camIO.flashStrobeFreq.valid = TRUE;
			pThis->m_camIO.flashStrobeFreq.type = PARAM_TYPE_STRING_LIST;
			DWORD cnt = *(DWORD*)pchRecvBuf;
			pThis->m_camIO.flashStrobeFreq.list.clear();
			for (DWORD i=0; i<cnt; i++)
			{
				std::string strInset = (char*)(pchRecvBuf + 4 + i*32);
				pThis->m_camIO.flashStrobeFreq.list.push_back(strInset);
			}

			//get resolution
			iret = pCmdToDev->SendCMD(CMD_IO_FLASH_STROBE_FREQ,CMD_METHOD_GET);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			pThis->m_camIO.flashStrobeFreq.strValue = (char*)pchRecvBuf;
		}

		//get JPEG OSD 
		iret = pCmdToDev->SendCMD(CMD_JPEG_OSD,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camOsd.jpegOsd.valid = TRUE;
			memcpy_s(pThis->m_camOsd.jpegOsd.value.p,sizeof(RoseekOsdConfig),pchRecvBuf,sizeof(RoseekOsdConfig));
		}

		//get H264 main stream OSD
		*(DWORD*)pchSendBuf = 0;
		iret = pCmdToDev->SendCMD(CMD_H264_OSD,CMD_METHOD_GET,pchSendBuf,4);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camOsd.h264Osd[0].valid = TRUE;
			memcpy_s(pThis->m_camOsd.h264Osd[0].value.p,sizeof(RoseekOsdConfig),pchRecvBuf,sizeof(RoseekOsdConfig));
		}

		//get H264 sub stream OSD
		*(DWORD*)pchSendBuf = 1;
		iret = pCmdToDev->SendCMD(CMD_H264_OSD,CMD_METHOD_GET,pchSendBuf,4);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camOsd.h264Osd[1].valid = TRUE;
			memcpy_s(pThis->m_camOsd.h264Osd[1].value.p,sizeof(RoseekOsdConfig),pchRecvBuf,sizeof(RoseekOsdConfig));
		}

		//get Iris control type
		iret = pCmdToDev->SendCMD(CMD_IRIS_TYPE, CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camIris.type.valid = TRUE;
			pThis->m_camIris.type.value.ui = *(DWORD*)pchRecvBuf;
		}

		if (pThis->m_camIris.type.value.ui == 1)
		{
			//DC-Iris
			iret = pCmdToDev->SendCMD(CMD_DCIRIS_CTRL,CMD_METHOD_GET);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camIris.dcirisMode.valid = TRUE;
				pThis->m_camIris.dcirisMode.value.ui = *(DWORD*)pchRecvBuf;
			}
		}
		else if (pThis->m_camIris.type.value.ui == 2)
		{
			//P-Iris
			iret = pCmdToDev->SendCMD(CMD_PIRIS_TYPE,CMD_METHOD_PARAMS_LIST);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camIris.pirisType.valid = TRUE;
				DWORD cnt = *(DWORD*)pchRecvBuf;

				for (DWORD i=0; i<cnt; i++)
				{
					std::string strInset = (char*)(pchRecvBuf + 4 + i*32);
					pThis->m_camIris.pirisType.list.push_back(strInset);
				}

				//get current lens type
				iret = pCmdToDev->SendCMD(CMD_PIRIS_TYPE,CMD_METHOD_GET);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				pThis->m_camIris.pirisType.strValue = (char*)pchRecvBuf;
			}

			if (pThis->m_camIris.pirisType.strValue != "None")
			{
				iret = pCmdToDev->SendCMD(CMD_PIRIS_FVALUE_CTRL,CMD_METHOD_PARAMS_LIST);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				if (result == CMD_PROCESS_SUCCESS)
				{
					DWORD cnt = *(DWORD*)pchRecvBuf;
					for (DWORD i=0; i<cnt; i++)
					{
						std::string strInset;
						strInset = strFormat("%2.2f",*(float*)(pchRecvBuf + 4 + i*4));
						pThis->m_camIris.pirisF.list.push_back(strInset);
					}
					pThis->m_camIris.pirisF.valid = TRUE;

					//get current F value
					iret = pCmdToDev->SendCMD(CMD_PIRIS_FVALUE_CTRL,CMD_METHOD_GET);
					if (iret != SEND_CMD_SUCCESS)
					{
						break;
					}
					pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
					result = pCmdToDev->GetCmdResult();
					float fPre = *(float*)pchRecvBuf;
					float fNext = *(float*)(pchRecvBuf + 4);
					if (fabs(fPre-fNext)<0.01)
					{
						pThis->m_camIris.pirisF.strValue = strFormat("%2.2f",fPre);
					}
					else
					{
						pThis->m_camIris.pirisF.strValue = strFormat("%2.2f~%2.2f",fPre,fNext);
					}
					
					pThis->m_camIris.pirisF.type = PARAM_TYPE_STRING_LIST;
				}

				//get step range
				iret = pCmdToDev->SendCMD(CMD_PIRIS_STEP_CTRL,CMD_METHOD_GET_RANGE);
				if (iret != SEND_CMD_SUCCESS)
				{
					break;
				}
				pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
				result = pCmdToDev->GetCmdResult();
				if (result == CMD_PROCESS_SUCCESS)
				{
					pThis->m_camIris.pirisStep.valid = TRUE;
					memcpy_s(&pThis->m_camIris.pirisStep.range,sizeof(ParamRange),pchRecvBuf+4,sizeof(ParamRange));

					iret = pCmdToDev->SendCMD(CMD_PIRIS_STEP_CTRL,CMD_METHOD_GET);
					if (iret != SEND_CMD_SUCCESS)
					{
						break;
					}
					pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
					result = pCmdToDev->GetCmdResult();
					pThis->m_camIris.pirisStep.value.ui = *(DWORD*)pchRecvBuf;
				}
			}	
		}
		//get JPEG picture storage state
		iret = pCmdToDev->SendCMD(CMD_SD_SAVE_JPEG,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camStore.saveJpgtoSD.valid = TRUE;
			pThis->m_camStore.saveJpgtoSD.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get DHCP state
		iret = pCmdToDev->SendCMD(CMD_NET_DHCP,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camNet.dhcp.valid = TRUE;
			pThis->m_camNet.dhcp.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get gateway
		iret = pCmdToDev->SendCMD(CMD_NET_GATEWAY,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camNet.gateway.valid = TRUE;
			pThis->m_camNet.gateway.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get subnet mask
		iret = pCmdToDev->SendCMD(CMD_NET_MASK,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camNet.mask.valid = TRUE;
			pThis->m_camNet.mask.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get DNS server
		//get subnet mask
		iret = pCmdToDev->SendCMD(CMD_NET_DNS_SERVER,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camNet.dnsServer.valid = TRUE;
			pThis->m_camNet.dnsServer.value.ui = *(DWORD*)pchRecvBuf;
		}

		//get NTP server ip address
		iret = pCmdToDev->SendCMD(CMD_NTP_SERVER,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camNet.ntpServer.valid = TRUE;
			pThis->m_camNet.ntpServer.value.ui = *(DWORD*)pchRecvBuf;
			pThis->m_camNet.ntpSyncTime.valid = TRUE;
			pThis->m_camNet.ntpSyncTime.value.ui = *(DWORD*)(pchRecvBuf+4);
		}

		//get FTP serve state
		iret = pCmdToDev->SendCMD(CMD_NET_FTP_SERVE,CMD_METHOD_GET);
		if (iret != SEND_CMD_SUCCESS)
		{
			break;
		}
		pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
		result = pCmdToDev->GetCmdResult();
		if (result == CMD_PROCESS_SUCCESS)
		{
			pThis->m_camNet.ftpServe.valid = TRUE;
			pThis->m_camNet.ftpServe.value.ui = *(DWORD*)pchRecvBuf;

			//get FTP server information
			iret = pCmdToDev->SendCMD(CMD_NET_FTP_SERVER_INFO,CMD_METHOD_GET);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camNet.ftpServerIP.valid = TRUE;
				pThis->m_camNet.ftpServerIP.value.ui = *(DWORD*)pchRecvBuf;

				pThis->m_camNet.ftpServerPort.valid = TRUE;
				pThis->m_camNet.ftpServerPort.value.ui = *(DWORD*)(pchRecvBuf+4);
			}

			//get FTP login information
			iret = pCmdToDev->SendCMD(CMD_NET_FTP_LOGIN_INFO,CMD_METHOD_GET);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camNet.ftpUserName.valid = TRUE;
				pThis->m_camNet.ftpUserName.type = PARAM_TYPE_STRING;
				pThis->m_camNet.ftpUserName.strValue = (char*)pchRecvBuf;

				pThis->m_camNet.ftpPassword.valid = TRUE;
				pThis->m_camNet.ftpPassword.type = PARAM_TYPE_STRING;
				pThis->m_camNet.ftpPassword.strValue = (char*)(pchRecvBuf+128);
			}
		}

		//get UART port state

		for (int i=0; i<3; i++)
		{
			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_UART_ENABLE,CMD_METHOD_GET,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camIO.UartPortState[i].valid = TRUE;
				pThis->m_camIO.UartPortState[i].value.ui = *(DWORD*)pchRecvBuf;
			}

			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_UART_BUADRATE,CMD_METHOD_GET,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camIO.UartPortBaudRate[i].valid = TRUE;
				pThis->m_camIO.UartPortBaudRate[i].value.ui = *(DWORD*)pchRecvBuf;
			}

			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_UART_BUADRATE,CMD_METHOD_GET,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camIO.UartPortBaudRate[i].valid = TRUE;
				pThis->m_camIO.UartPortBaudRate[i].value.ui = *(DWORD*)pchRecvBuf;
			}

			*(DWORD*)pchSendBuf = i;
			iret = pCmdToDev->SendCMD(CMD_UART_WORKMODE,CMD_METHOD_GET,pchSendBuf,4);
			if (iret != SEND_CMD_SUCCESS)
			{
				break;
			}
			pchRecvBuf = const_cast<char*>(pCmdToDev->GetBackDataPtr());
			result = pCmdToDev->GetCmdResult();
			if (result == CMD_PROCESS_SUCCESS)
			{
				pThis->m_camIO.UartPortWorkMode[i].valid = TRUE;
				pThis->m_camIO.UartPortWorkMode[i].value.ui = *(DWORD*)pchRecvBuf;
			}
		}



		iret = 0;
	} while (0);
	
	::PostMessage(pThis->m_hWndNotify, WM_MSG_GET_PARAM_FINISH, (WPARAM)iret, 0);
	return 0;
}

int CDevParams::CloseObtainParams()
{
	if (m_hThreadGetParam!=NULL)
	{
		CloseHandle(m_hThreadGetParam);
		m_hThreadGetParam = NULL;
	}
	return 0;
}

int	CDevParams::LoadPortNumInfo(BYTE* pInfo)
{
	DWORD num = *(DWORD*)pInfo;
	RoseekPortNumInfo *pPortNumInfo;
	CString str;
	DWORD port;
	USES_CONVERSION;
	m_mapPortNum.clear();
	for (DWORD i=0; i<num; i++)
	{
		pPortNumInfo = (RoseekPortNumInfo*)(pInfo+4+i*sizeof(RoseekPortNumInfo));
		str = A2T(pPortNumInfo->description);
		port = pPortNumInfo->portNum;
		m_mapPortNum.insert(std::make_pair(str,port));
	}
	return 0;
}

DWORD CDevParams::FindPortNum(CString portName)
{
	std::map<CString,  DWORD>::iterator itMap;
	itMap = m_mapPortNum.find(portName);
	if (itMap == m_mapPortNum.end())
	{
		return 0;
	}
	return itMap->second;
}


//get information of device
BOOL CDevParams::QueryDevInfo(const char *pIP, int port, char *buff, int size)
{
	SOCKET sockThis;
	BYTE cmd[10];
	BOOL bRet;
	int recved, ret;

	bRet = FALSE;
	sockThis = INVALID_SOCKET;
	do 
	{
		sockThis = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
		if (sockThis == INVALID_SOCKET)
		{
			break;
		}
		int nTimeOut = 1000;
		setsockopt(sockThis, SOL_SOCKET, SO_SNDTIMEO, (char*)&nTimeOut, sizeof(nTimeOut));
		setsockopt(sockThis, SOL_SOCKET, SO_RCVTIMEO, (char*)&nTimeOut, sizeof(nTimeOut));

		struct sockaddr_in addrCam;
		addrCam.sin_family = AF_INET;
		addrCam.sin_addr.s_addr = inet_addr(pIP);

		addrCam.sin_port = htons((u_short)port);
		if (!ConnectHasTimeout(sockThis, &addrCam, 3000))
		{
			break;
		}

		memset(cmd, 0, sizeof(cmd));
		cmd[0] = 0x85;			
		if (!SafeSend(sockThis, (char*)&cmd, 5))
		{
			break;
		}

		recved = 0;
		while (recved < size - 1)
		{
			ret = recv(sockThis, buff + recved, size - 1 - recved, 0);
			if (ret <= 0)
			{
				break;
			}
			recved += ret;
		}
		buff[recved] = '\0';

		bRet = TRUE;
	} while(0);

	if (sockThis != INVALID_SOCKET)
	{
		closesocket(sockThis);
	}

	return bRet;
}




//get camera information
int CDevParams::AnalyCameraInfo(const char* pVersion)
{

	USES_CONVERSION;
	CString strInfo = A2T(pVersion);
	size_t nFind = 0;
	size_t nFrom = 0;
	int nVersion = 0;
	if (pVersion == NULL)
	{
		return -1;
	}

	nFind = strInfo.Find(_T("Camera Name :"),nFrom);
	if (nFind != -1)
	{
		//old information used by EagleEye3
		nVersion = CAM_INFO_VERSION_1_00;
	}
	else
	{
		//new information used by EagleEye3E/EagleEye4/EagleEye5
		nFind = strInfo.Find(_T("Equipment Name:"),nFrom);
		if (nFind != std::string::npos)
		{
			nVersion = CAM_INFO_VERSION_1_01;
		}
	}

	if (strstr(T2A(strInfo.GetBuffer(0)),"HardwareMixVersion:")!=NULL)
	{
		nVersion = CAM_INFO_VERSION_1_02;
	}

	if (nVersion == CAM_INFO_VERSION_1_00)
	{
		nFrom = nFind + 15;

		nFind = strInfo.Find(_T("SN :"),nFrom);
		m_camState.strModel = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 5;

		nFind = strInfo.Find(_T("CPU ID :"),nFrom);
		m_camState.strSN = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));


		nFrom = nFind + 9;

		nFind = strInfo.Find(_T("Registered Modules Information :"),nFrom);
		m_camState.strCpuId = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		m_camState.strMainBoardVer = "NA";
		m_camState.strMainBoardMfn = "NA";
		m_camState.strSensorType = "NA";
		m_camState.strSensorBoardVer =  "NA";
		m_camState.strHardwareMixVersion = "NA";
		m_camState.strFirmwareMixVersion = "NA";

		m_camState.strSeries = "EagleEye3";
	}
	else if (nVersion == CAM_INFO_VERSION_1_01)
	{
		nFrom = nFind + 16;

		nFind = strInfo.Find(_T("SN:"),nFrom) ;
		m_camState.strModel = T2A(strInfo.Mid(nFrom,nFind - 1 - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 3;

		nFind = strInfo.Find(_T("CPU ID:"),nFrom);
		m_camState.strSN = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		if (m_camState.strSN.find("NONE") != std::string::npos)
		{
			m_camState.strSN = "NA";
		}

		nFrom = nFind + 7;

		nFind = strInfo.Find(_T("Main Board Version:"),nFrom);
		m_camState.strCpuId = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 20;

		nFind = strInfo.Find(_T("Main Board Mfn:"),nFrom);
		m_camState.strMainBoardVer = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 15;

		nFind = strInfo.Find(_T("Sensor Type:"),nFrom);
		m_camState.strMainBoardMfn = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 12;

		nFind = strInfo.Find(_T("Sensor Board Version:"),nFrom);
		m_camState.strSensorType = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 21;

		nFind = strInfo.Find(_T("Registered Modules Information:"),nFrom);
		m_camState.strSensorBoardVer = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		if (m_camState.strModel.find("NONE") != std::string::npos)
		{
			//no model information
			m_camState.strSeries = "NA";
			m_camState.strModel = "NA";
		}
		else
		{
			char index[2];
			index[0] =  m_camState.strModel.at(4);
			index[1] = 0;
			m_camState.strSeries = strFormat("EagleEye%s",&index);
			if (m_camState.strModel.find("GE") != std::string::npos)
			{
				m_camState.strSeries += 'E';
			}
		}	
		m_camState.strHardwareMixVersion = "NA";
		m_camState.strFirmwareMixVersion = "NA";
	}
	else if (nVersion == CAM_INFO_VERSION_1_02)
	{
		nFrom = nFind + 16;

		nFind = strInfo.Find(_T("SN:"),nFrom) ;
		m_camState.strModel = T2A(strInfo.Mid(nFrom,nFind - 1 - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 3;

		nFind = strInfo.Find(_T("HardwareMixVersion:"),nFrom);
		m_camState.strSN = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		if (m_camState.strSN.find("NONE") != std::string::npos)
		{
			m_camState.strSN = "NA";
		}

		nFrom = nFind + 19;
		nFind = strInfo.Find(_T("FirmwareMixVersion:"),nFrom);
		m_camState.strHardwareMixVersion = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 19;
		nFind = strInfo.Find(_T("CPU ID:"),nFrom);
		m_camState.strFirmwareMixVersion = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 7;

		nFind = strInfo.Find(_T("Main Board Version:"),nFrom);
		m_camState.strCpuId = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 20;

		nFind = strInfo.Find(_T("Main Board Mfn:"),nFrom);
		m_camState.strMainBoardVer = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 15;

		nFind = strInfo.Find(_T("Sensor Type:"),nFrom);
		m_camState.strMainBoardMfn = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 12;

		nFind = strInfo.Find(_T("Sensor Board Version:"),nFrom);
		m_camState.strSensorType = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 21;

		nFind = strInfo.Find(_T("Registered Modules Information:"),nFrom);
		m_camState.strSensorBoardVer = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		if (m_camState.strModel.find("NONE") != std::string::npos)
		{
			//no model information
			m_camState.strSeries = "NA";
			m_camState.strModel = "NA";
		}
		else
		{
			char index[2];
			if (m_camState.strModel.find("RMVA") != std::string::npos)
			{
				index[0] = m_camState.strModel.at(4);
				index[1] = 0;
				m_camState.strSeries = strFormat("EagleEye%d",atoi(&index[0]));
				if (m_camState.strModel.find("GE") != std::string::npos)
				{
					m_camState.strSeries += 'E';
				}
			}
			else if(m_camState.strModel.find("RSCM",0) != std::string::npos)
			{
				
				index[0] = m_camState.strModel.at(4);
				index[1] = 0;
				m_camState.strSeries = strFormat("Chameleon%d",atoi(&index[0]));
			}
			else if (m_camState.strModel.find("RSGK",0) != std::string::npos)
			{
				index[0] = m_camState.strModel.at(4);
				m_camState.strSeries = strFormat("Gecko%d",atoi(&index[0]));
			}
			else if (m_camState.strModel.find("RSCT",0) != std::string::npos)
			{
				index[0] = m_camState.strModel.at(4);
				m_camState.strSeries = strFormat("Cheetah%d", atoi(&index[0]));
			}
			else
			{
				m_camState.strSeries = "NA";
			}
		}
	}

	nFrom = nFind + 33;

	nFind = strInfo.Find(_T("Name:"),nFrom);

	int nModuleNums = 0;

	while (1)
	{
		nFrom = nFind + 5;

		nFind = strInfo.Find(_T("Version:"),nFrom);
		m_camState.moduleInfo[nModuleNums].strName = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 8;

		nFind = strInfo.Find(_T("Date:"),nFrom);
		m_camState.moduleInfo[nModuleNums].strVer = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 5;

		nFind = strInfo.Find(_T("Description:"),nFrom);
		m_camState.moduleInfo[nModuleNums].strDate = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));

		nFrom = nFind + 13;

		nFind = strInfo.Find(_T("Name:"),nFrom);

		if (nFind != -1)
		{
			m_camState.moduleInfo[nModuleNums].strDescription = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));
			nModuleNums++;
		}
		else
		{
			nFind = strInfo.GetLength();
			m_camState.moduleInfo[nModuleNums].strDescription = T2A(strInfo.Mid(nFrom,nFind - nFrom).Trim().GetBuffer(0));
			nModuleNums++;
			break;
		}
	}
	m_camState.nModuleNum = nModuleNums;

	int index = m_camState.strModel.find('-', 0);
	if (index != std::string::npos)
	{
		int nFindIndex = m_camState.strModel.find("SD", index);
		if (nFindIndex != std::string::npos)
		{
			m_camState.strSD = m_camState.strModel.substr(nFindIndex+2,3);
		}
		else
		{
			nFindIndex = m_camState.strModel.find('H', index);
			if (nFindIndex != std::string::npos)
			{
				m_camState.strSD = m_camState.strModel.substr(nFindIndex+1,4);
			}			
		}
	}

	if ((m_camState.strSD == "")||(m_camState.strSD == "00G")||(m_camState.strSD == "000G"))
	{
		m_camState.strSD = "NA";
	}
	else
	{
		m_camState.strSD += "-Byte";
	}
	
	while(1)
	{
		if (m_camState.strSD == "")
		{
			break;
		}
		if (m_camState.strSD.at(0) != '0')
		{
			break;
		}
		m_camState.strSD.erase(0,1);
	}

	return 0;
}



